package com.carltechnology.mahjonggamecaculation.views.impl;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.carltechnology.mahjonggamecaculation.R;
import com.carltechnology.mahjonggamecaculation.dao.DataManager;
import com.carltechnology.mahjonggamecaculation.presenter.IMahjongChoosePresenter;
import com.carltechnology.mahjonggamecaculation.presenter.impl.MahjongChoosePresenter;
import com.carltechnology.mahjonggamecaculation.views.IMahjongChooseView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by WZTCM on 2016/6/28.
 */
public class MahjongChooseActivity extends AppCompatActivity implements IMahjongChooseView{

    private IMahjongChoosePresenter presenter;
    @InjectView(R.id.mahjongchoose_item_list)
    RecyclerView mRecyclerView;
    @InjectView(R.id.mahjongchoose_toolbar)
    Toolbar mToolBar;
    private Handler handler = new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mahjongchoose);
        ButterKnife.inject(this);
        setSupportActionBar(mToolBar);
        mToolBar.setTitle(getTitle());
        assert mRecyclerView!=null;
        presenter = MahjongChoosePresenter.newInstance(this);



    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.showGameData();
    }

    @Override
    public AppCompatActivity getSelf() {
        return this;
    }

    @Override
    public RecyclerView getRecyclerView() {
        return mRecyclerView;
    }

    @Override
    public void toDetailView() {
        Intent intent = new Intent(this, MahjongDetailActivity.class);
        startActivity(intent);
    }

    @Override
    public Handler getHandler() {
        return handler;
    }

    @OnClick(R.id.mahjongchoose_fab)
    public void onCreateNewGame(View view){
        Intent intent = new Intent(this,MahjongGameInputActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DataManager.getInstance().closeDataBase();
    }
}
